import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/assets/assets.dart';
import 'package:pornhub_app/assets/styles.dart';
import 'package:pornhub_app/components/app_bg_view.dart';
import 'package:pornhub_app/components/image_view.dart';
import 'package:pornhub_app/components/save_screen/save_screen.dart';
import 'package:pornhub_app/components/text_view.dart';
import 'package:pornhub_app/generate/app_image_path.dart';
import 'package:pornhub_app/utils/app_utils.dart';
import 'package:pornhub_app/utils/extension.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:screenshot/screenshot.dart';

import '../../../../utils/color.dart';
import 'agent_page_controller.dart';

///代理赚钱
class AgentPage extends GetView<AgentPageController> {
  const AgentPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _buildBodyView(),
    );
  }

  _buildBodyView() {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: SingleChildScrollView(
        child: Column(
          children: [
            // ///用户信息
            // 20.verticalSpace, _buildUserInfoView(),

            // ///提现金额
            // 20.verticalSpace, _buildWithdrawAmountView(),

            ///二维码推广
            20.verticalSpace, _buildAgentShareView(),

            ///保存和分享
            30.verticalSpace, _buildSaveAndShareView(),

            ///常见问题图片
            40.verticalSpace,
            _buildAgentFaq()
            // Image.asset(
            //   AppImagePath.mine_agent_faq_desc,
            //   fit: BoxFit.fitWidth,
            // ),
            // 40.verticalSpace,
          ],
        ),
      ),
    );
  }

  ///二维码推广
  _buildAgentShareView() {
    return Container(
      width: 330.w,
      height: 469.w,
      decoration: BoxDecoration(
          color: COLOR.hexColor("010101"),
          border: Border.all(color: COLOR.hexColor("#ff9000"))),
      alignment: Alignment.bottomCenter,
      child: CarouselSlider.builder(
        options: CarouselOptions(
            autoPlay: false,
            height: 469.w,
            enlargeCenterPage: true,
            enlargeStrategy: CenterPageEnlargeStrategy.zoom,
            // 显示比例
            viewportFraction: 1,
            pageSnapping: true,
            // 启用无限循环
            enableInfiniteScroll: true,
            initialPage: 0,
            onPageChanged: (index, reason) {
              controller.index = index;
            }),
        itemCount: controller.cardTestList.length,
        itemBuilder: (context, index, pageViewIndex) {
          return Screenshot(
            controller: controller.screenshotControllers[index],
            child: AppBgView(
              width: 330.w,
              height: 469.w,
              imagePath: controller.cardTestList[index],
              alignment: Alignment.bottomCenter,
              padding: EdgeInsets.symmetric(horizontal: 0.w, vertical: 0.w),
              // radius: 6.w,
              child: index == 2
                  ? Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        QrImageView(
                          padding: EdgeInsets.all(1.w),
                          data: controller.url.value,
                          size: 110.w,
                          backgroundColor: Colors.white,
                        ),
                        40.verticalSpace,
                      ],
                    )
                  : Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        QrImageView(
                          padding: EdgeInsets.all(1.w),
                          data: controller.url.value,
                          size: 110.w,
                          backgroundColor: Colors.white,
                        ),
                        4.horizontalSpace,
                        Container(
                          width: 193.w,
                          height: 110.w,
                          padding: EdgeInsets.all(14.w),
                          decoration: BoxDecoration(
                              image: DecorationImage(
                                  image: AssetImage(
                                      AppImagePath.mine_agent_code_bg))),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              TextView(
                                text: "我的推广码：",
                                color: COLOR.hexColor("#dba152"),
                                fontSize: 18.w,
                              ),
                              TextView(
                                text: "${controller.inviteCode.value}",
                                color: COLOR.hexColor("#dba152"),
                                fontSize: 20.w,
                                fontWeight: FontWeight.w600,
                              ),
                              TextView(
                                text: "${controller.domainFromUrl.value}",
                                color: COLOR.white.withValues(alpha: 0.8),
                                fontSize: 14.w,
                                fontWeight: FontWeight.w400,
                              ),

                              // Expanded(
                              //     child: Column(
                              //   mainAxisSize: MainAxisSize.min,
                              //   mainAxisAlignment: MainAxisAlignment.end,
                              //   crossAxisAlignment: CrossAxisAlignment.start,
                              //   children: [
                              //     Row(
                              //       children: [
                              //         // Obx(() => TextView(
                              //         //       text: controller.inviteCode.value,
                              //         //       color: index == 0
                              //         //           ? COLOR.color_7FFCCD
                              //         //           : index == 3
                              //         //               ? COLOR.color_F2BF62
                              //         //               : COLOR.color_B940FF,
                              //         //       fontSize: 16.w,
                              //         //     )),
                              //       ],
                              //     ),
                              //     2.verticalSpace,
                              //     TextView(
                              //       text: "若扫码无法打开，请在浏览器手动输入下方地址，即可访问产品",
                              //       color: COLOR.white,
                              //       fontSize: 10.w,
                              //     ),
                              //     2.verticalSpace,
                              //     Obx(() => TextView(
                              //           text: controller.domainFromUrl.value,
                              //           color: COLOR.white,
                              //           fontSize: 10.w,
                              //         )),
                              //   ],
                              // )),
                              10.horizontalSpace,
                              // Column(
                              //   mainAxisSize: MainAxisSize.min,
                              //   mainAxisAlignment: MainAxisAlignment.center,
                              //   crossAxisAlignment: CrossAxisAlignment.end,
                              //   children: [
                              //     QrImageView(
                              //       padding: EdgeInsets.all(1.w),
                              //       data: controller.url.value,
                              //       size: 86.w,
                              //       backgroundColor: Colors.white,
                              //     ),
                              //     3.verticalSpace,
                              //     TextView(
                              //       text: "请用浏览器扫码打开",
                              //       color: COLOR.white,
                              //       fontSize: 10.w,
                              //     ),
                              //   ],
                              // ),
                            ],
                          ),
                        )
                      ],
                    ).paddingBottom(16.w),
            ),
          );
        },
      ),
    );
  }

  ///保存和分享
  _buildSaveAndShareView() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        Image.asset(
          AppImagePath.mine_agent_save_picture,
          height: 48.w,
          fit: BoxFit.fitHeight,
        ).onTap(() {
          SaveScreen.onCaptureClick(
              Get.context!, controller.screenshotControllers[controller.index],
              isBack: false);
        }),
        Image.asset(
          AppImagePath.mine_agent_copy_link,
          height: 48.w,
          fit: BoxFit.fitHeight,
        ).onTap(() {
          AppUtils.copyToClipboard(controller.url.value);
        }),
      ],
    );
  }

  _buildAgentFaq() {
    return Column(
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: 77.w,
              height: 1,
              decoration: BoxDecoration(
                  gradient: LinearGradient(colors: [
                const Color.fromRGBO(255, 144, 0, 0),
                COLOR.hexColor("#ff9000")
              ])),
            ),
            TextView(
              text: "分享奖励",
              style: kTextStyle(COLOR.hexColor("#ff9000"), fontsize: 18.w),
            ).marginHorizontal(12.w),
            Container(
              width: 77.w,
              height: 1,
              decoration: BoxDecoration(
                  gradient: LinearGradient(
                      begin: Alignment.centerRight,
                      end: Alignment.centerLeft,
                      colors: [
                    const Color.fromRGBO(255, 144, 0, 0),
                    COLOR.hexColor("#ff9000"),
                  ])),
            ),
          ],
        ),
        ImageView(
          src: AppImagePath.mine_agent_faq_1,
          width: 332.w,
          height: 106.w,
        ).marginOnly(top: 13.w, bottom: 10.w),
        ImageView(
          src: AppImagePath.mine_agent_faq_2,
          width: 332.w,
          height: 145.w,
        )
      ],
    );
  }
}
